package org.openarmory.gui.components;

import java.util.Arrays;

import org.openarmory.gui.domain.ArmoryPageRetrieveFieldFactory;
import org.openarmory.gui.pojo.ArmoryPageRetrieveBean;

import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
import com.vaadin.ui.GridLayout;

public class ArmoryPageRetrieveForm extends Form {

	private GridLayout retrieveLayout;
	
	public ArmoryPageRetrieveForm(BeanItem<ArmoryPageRetrieveBean> pageRetrieveItem){
		setCaption("Character information");
		
		retrieveLayout = new GridLayout(3, 3);
		retrieveLayout.setMargin(true, false, false, true);
		retrieveLayout.setSpacing(true);
		
		setLayout(retrieveLayout);
		setWriteThrough(false);
		setInvalidCommitted(false);
		
		setFormFieldFactory(new ArmoryPageRetrieveFieldFactory());
		setItemDataSource(pageRetrieveItem);
		
		setVisibleItemProperties(Arrays.asList(new String[] {"zone", "realm", "characterName", "dataType"}));
		
		
	}
	
	@Override
	protected void attachField(Object propertyId, Field field) {
		if (propertyId.equals("zone")) {
			retrieveLayout.addComponent(field, 0, 0);
        } else if (propertyId.equals("realm")) {
        	retrieveLayout.addComponent(field, 1, 0);
        } else if (propertyId.equals("characterName")) {
        	retrieveLayout.addComponent(field, 0, 2);
        } else if (propertyId.equals("dataType")) {
        	retrieveLayout.addComponent(field, 1, 2);
        }
	}
}
